#include <CType.h>
#include <MyLib.h>

extern void Prepare32();

main()
{
    int8_t *p;
    int8_t cmd[100];
    DiskInfo MyDi;
    FileInfo * fi, tfi;
    int8_t bfr[129];
    int16_t i;

    printf("\nHello this is my OS:\nSystem date and time:");

    displayDateTime(3);

    memcpy(&MyDi, loadDrvInfo(0), sizeof(MyDi));

    printf("\nPlease input command\n");

    while(1)
        {
        printf("*>");

        p = conInput(99);

        memcpy(cmd, p, 99);

        cmd[99] = '\0';
        p = strtrim(strupr(cmd));

        if (strlen(p) == 0)
            continue;

        if (strcmp(p, "CLS") == 0)
            {
            clrscr();
            }
        else if (strcmp(p, "TIME") == 0)
            {
            printf("System date and time:");

            displayDateTime(3);

            printf("\n");
            }
        else if (strcmp(p, "DOSEXIT") == 0)
            {
            dosExit();
            }
        else if (strcmp(p, "DIR") == 0)
            {
            DispAllFile(&MyDi);
            }
        else if (strcmp(p, "TO32") == 0)
            {
            if (loadPE("K32.EXE", &MyDi) != 0)
                {
                printf("Failed to load kernel file\n");
                }
            else
                {
                printf("Press any key to go...\n");
                getCh();
                Prepare32();
                }
            }
        else if (memcmp(p, "TYPE ", 5) == 0)
            {
            p += 5;
            p = strtrim(p);

            fi = searchFile(p, &MyDi);

            memcpy(&tfi, fi, sizeof(FileInfo));

            if (fi == NULL)
                {
                printf("File not found - %s\n", p);
                }
            else
                {

                printf("File context %s:\n", p);

                for (i = 0; i < tfi.Length; i += 128)
                    {
                    bfr[128] = '\0';
                    readFile(bfr, &tfi, i, 128);
                    printf("%s", bfr);
                    }

                printf("\n");
                }
            }
        else
            {
            printf("%s - unknown command\n", p);
            }
        }
LblLoop:
    goto LblLoop;
}



